<script>
	import {
		mapMutations
	} from 'vuex';
	import cache from 'common/cache.js'
	import t from 'common/tabbar.js'
	export default {
		onLaunch: function() {
			var that = this
			// 自动登录
			this.getloginuser()
			// #ifdef APP-PLUS
			/**
			 * 自定义tabbar
			 */
			// 点击状态
			let selectedData = [
				'http://cdn.sdzuhaoxia.com/icon/index/shouye-icon.png',
				'http://cdn.sdzuhaoxia.com/icon/index/zuhao-icon.png',
				'http://cdn.sdzuhaoxia.com/icon/index/fahao-icon.png',
				'http://cdn.sdzuhaoxia.com/icon/index/xiaoxi-icon.png',
			]
			// 未点击状态
			let iconData = [
				'https://cdn.sdzuhaoxia.com/photo/game/808a26819ee5418d89afd9351ea040f3.png',
				'https://cdn.sdzuhaoxia.com/photo/game/a751fbd26b4d4cde97844f2ac0ac8d3f.png',
				'https://cdn.sdzuhaoxia.com/photo/game/e060d5ac23694ccdb32d22702c011bfb.png',
				'https://cdn.sdzuhaoxia.com/photo/game/2eae03580dc5492f95d3e87cfc1fee9d.png',
			]
			// 根据缓存判断是否下载过改图片防止重复下载
			let yes = cache.fetchCache(cache.CLICKSTATUS) // 缓存保存临时路径
			let no = cache.fetchCache(cache.NOCLICKSTATUS) // 缓存保存临时路径
			if (yes && no) {
				// 获取下载好的图片
				// t.aglinTabbar(no,yes)
			} else {
				// t.tabbar(iconData,selectedData)
			}
			// 获取主题
			this.getthemeColor();
			// 锁定屏幕方向
			plus.screen.lockOrientation('portrait-primary'); //锁定
			//监听系统通知栏消息点击事件
			plus.push.addEventListener('click', function(msg) {
				//处理点击消息的业务逻辑代码  
				setTimeout(function() {
					let payload = JSON.parse(msg.payload)
					if (payload.pages) {
						uni.navigateTo({
							url: `/pages/${payload.pages}?id=${payload.id}`,
						})
					}
				}, 1000);
			}, true);
			//监听接收透传消息事件  
			plus.push.addEventListener('receive', function(msg) {
				//处理透传消息的业务逻辑代码  
				setTimeout(function() {
					let payload = JSON.parse(msg.payload)
					if (payload.pages) {
						uni.navigateTo({
							url: `/pages/${payload.pages}?id=${payload.id}`,
						})
					}
				}, 1000);
			}, true);
			//#endif
		},
		onShow: function() {
			console.log('App Show')
			// 判断外部链接调用app
			// #ifdef APP-PLUS
			setTimeout(() => {
				var args = plus.runtime.arguments;
				if (args) {
					// console.log(args)
				}
			}, 1000)
			// #endif
		},
		onHide: function() {
			console.log('App Hide')
		},
		onError: function(err) {
			console.log(err)
		},
		methods: {
			...mapMutations(['login']),
			/**
			 * 通过接口获取用户信息拿到了就是登录没拿到表示未登录
			 */
			// 获取登录信息
			getloginuser() {
				this.$api.getloginuser().then(res => {
					const {
						result,
						info,
						data
					} = res.data
					if (result === 1) {
						this.login(data.member)
					}
				}).catch((err) => {}).finally((e) => {})
			},

			//获取主题
			getthemeColor() {
				let themeColor = this.themeColor
				// uni.setNavigationBarColor({
				//     frontColor: '#000000',
				//     backgroundColor: '#ff0000',
				//     animation: {
				//         duration: 400,
				//         timingFunc: 'easeIn'
				//     }
				// })

			}

		}
	}
</script>

<style lang="scss">
	/* #ifndef APP-PLUS-NVUE */
	@import url("/static/main.css");

	/*每个页面公共css */
	page {
		font-size: 28rpx;
	}

	/* input 样式 */
	.input-placeholder {
		color: #999999;
	}

	.placeholder {
		color: #999999;
	}

	/* #endif */
</style>
